package com.briup.jz.web.controller;

import com.briup.jz.bean.AccountApply;
import com.briup.jz.bean.extend.AccountApplyExtend;
import com.briup.jz.service.IAccountApplayService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/accountapply")
@Api(description="账户变动申请相关接口")
public class AccountApplyController {

   @Autowired
    private IAccountApplayService accountApplayService;
    @ApiOperation("提交账户变动申请")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "money" ,value = "金额", paramType = "form",required = true),
            @ApiImplicitParam(name = "applyType" ,value = "种类", paramType = "form",required = true),
            @ApiImplicitParam(name = "status" ,value = "状态", paramType = "form"),
            @ApiImplicitParam(name = "userId" ,value = "用户id", paramType = "form",required = true),
    })
    @PostMapping("/saveOrUpdate")
    public Message saveOrUpdate(AccountApply accountApply){
        accountApplayService.saveOrUpdate(accountApply);

        return MessageUtil.success("操作成功");
    }
    @ApiOperation("撤销账户变动申请")
    @ApiImplicitParam(value = "申请主键id", name="id",paramType = "query",required = true)
    @GetMapping("/delete")
    public Message delete(Long id){
        accountApplayService.deleteById(id);
        return MessageUtil.success("操作成功");
    }

    @ApiOperation("查询账户变动申请信息")
    @GetMapping("/query")
    public Message query(Long id){
        List<AccountApply> accountApplies = accountApplayService.query(id);
        return MessageUtil.success(accountApplies);
    }
    @ApiOperation("审核不通过")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "申请主键id", name="id",paramType = "query",required = true),
            @ApiImplicitParam(value = "拒绝原因", name="reason",paramType = "form"),
    })
    @GetMapping("checkNoPass")
    public  Message checknopass(Long id,String reason){
        accountApplayService.checkNoPass(id,reason);
        return MessageUtil.success("修改成功");
    }
    @ApiOperation("审核不通过")

    @ApiImplicitParam(value = "申请主键id", name="id",paramType = "query",required = true)

    @GetMapping("checkPass")
    public  Message checkpass(Long id){
        accountApplayService.checkPass(id);
        return MessageUtil.success("修改成功");
    }

    @GetMapping("/querywithuser")
    @ApiOperation("查找申请并查出所属用户")
    public  Message queryWithUser(Long id){
        List<AccountApplyExtend> accountApplyExtends = accountApplayService.querywithuser(id);
       return MessageUtil.success(accountApplyExtends);
    }
}
